// Package cmd /*
package cmd

import (
	"cmd-tools/translate"
	"github.com/fatih/color"

	"github.com/spf13/cobra"
)

// translationCmd represents the translate command
var translationCmd = &cobra.Command{
	Use:   "translate",
	Short: "中英互译",
	Long:  "中英互译",
	Run: func(cmd *cobra.Command, args []string) {
		target := cmd.Flag("target").Value.String()
		source, err := translate.NewTranslation().Do(target)
		if err != nil {
			color.Red("翻译失败")
		}
		color.Green("翻译结果：%s\n", source)
	},
}

func init() {
	rootCmd.AddCommand(translationCmd)

	translationCmd.Flags().StringP("target", "t", "", "目标翻译词")
	err := translationCmd.MarkFlagRequired("target")
	if err != nil {
		color.Red("参数不存在")
	}
}
